<template>
    <view class="container">
        <header-bar :config="config"></header-bar>
		   <stock-list
				ref="stockList"
				:dataZero="dataZero"
				:stockArr="stockArr"
				:pCodeArr="pCodeArr"
				:code="code"
				:organizationsArr="organizationsArr"
				:GroupCodeArr="GroupCodeArr"
				@totalBack="waitTotalBack"></stock-list>
        <view @click="goHome()"  class="returnHome">返回<br/>首页</view>
		<view @click="easyGoBack()" class="returnUp">返回<br/>上级</view>
    </view>
</template>

<script>
import { mapMutations, mapState, mapGetters } from "vuex"
import { getElementHeight } from "@/uni-sub-base/utils/elementUtil.js"
import stockList from "./stock-list.vue"
import storage from "@/uni-sub-base/utils/storage.js"
export default {
    components: {
		stockList,
	},
    data() {
        return {
            config: {
                title: "库存状况",
                centerSlot: true,
                rightSlot: false,
            },
            mainColor: "",
            client: "",
			dataZero:'0',
			stockArr:'',
			pCodeArr:'',
			code:'',
			organizationsArr:'',
			GroupCodeArr:'',
			sublistHeight: "",
        }
    },
    watch: {

    },
    computed: {
        ...mapGetters(["getValetCartData"]),
    },
    created() {
    },
    onLoad(e) {
        if (e.dataZero) {
            // this.valetUserInfo = JSON.parse(decodeURIComponent(e.valetUserInfo))
            this.dataZero = e.dataZero
        }
        if (e.stockArr) {
            this.stockArr = e.stockArr
        }
        if (e.pCodeArr) {
           this.pCodeArr = e.pCodeArr
        }
		if (e.organizationsArr) {
		   this.organizationsArr = e.organizationsArr
		}
		if (e.title) {
		   this.config.title = e.title
		}else{
			this.config.title = '库存状况'
		}
		if(e.code){
			this.code = e.code
		}
		if(e.GroupCodeArr){
			this.GroupCodeArr = e.GroupCodeArr
		}
    },
    mounted() {
	   setTimeout(() => {
	       if (this.$refs.stockList) {
	           this.$refs.stockList.refresh()
	       }
	   }, 300)
    },
    onShow() {
       
    },
	onBackPress(options) {
	storage.setCache("returnNum",storage.getCache("returnNum")-1)
	console.log(storage.getCache("returnNum"));
	if (options.from === 'navigateBack') {
		console.log('返回按钮被点击');
	  let returnCler = storage.getCache("returnClear")
	  if(returnCler){
		  storage.removeCache("returnClear")
		  uni.navigateBack({
		      delta: storage.getCache("returnNum")+1
		  });
		  storage.removeCache("returnNum")
		  // this.easyGoTo('/pages/stock/index')
		  return true;
	  }else{
		  return false;
	  }
	  // 在这里可以执行你想要的操作
	  // 返回 true 表示阻止默认返回行为，返回 false 则不阻止
	}
	// 如果不是 navigateBack 触发的返回，不阻止默认行为
	return false;
	},
    methods: {
		waitTotalBack(){
			
		},
        goHome(){
			storage.setCache("returnClear",1)
			storage.setCache("returnNum",storage.getCache("returnNum")+1)
            this.easyGoTo(`/pages/stock/detail?dataZero` + this.dataZero + '&stockArr=' + this.stockArr +'&pCodeArr=' + this.pCodeArr +'&organizationsArr=' + this.organizationsArr+'&GroupCodeArr='+this.GroupCodeArr)
        }
    },
}
</script>

<style lang="scss">
.detail-card {
    margin: 24rpx;
    height: 172rpx;
    padding: 32rpx 0 32rpx 40rpx;
    box-sizing: border-box;
    background: $app-color-main;
    color: $color-white;
    box-shadow: 0rpx 10rpx 28rpx 0rpx rgba(0, 0, 0, 0.06);
    border-radius: 22rpx;
    .sale-money {
        .text {
            margin-bottom: 12rpx;
            font-size: 28rpx;
        }
        .price {
            display: flex;
            align-items: flex-end;
            font-weight: 700;

            .unit {
                margin-bottom: 6rpx;
            }

            .num {
                margin-left: 6rpx;
                font-size: 48rpx;
            }
        }
    }
    .count-wrapper {
        display: flex;
        margin-top: 12rpx;
        .left,
        .right {
            flex: 1;
            .text {
                margin-bottom: 12rpx;
                font-size: 24rpx;
            }

            .count {
                font-weight: 700;
                font-size: 44rpx;
            }
        }

        .right {
            .count {
                display: flex;
                align-items: flex-end;
                .unit {
                    margin-bottom: 6rpx;
                    font-size: 24rpx;
                }
            }
        }
    }
}

.list-header {
    display: flex;
    align-items: center;
    height: 80rpx;
    padding-left: 32rpx;
    // padding-right: 60rpx;
    background: #ffffff;
    box-shadow: 0px 6rpx 10rpx 0rpx rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 1;

    .left-wrapper,
    .right-wrapper {
        flex: 1;
        display: flex;
        align-items: center;
    }

    .right-wrapper {
        .h-item {
            flex: 1;
        }
    }

    .h-item {
        text-align: center;
        font-size: $size-28;
        font-weight: bold;

        &.h-name {
            margin-left: 48rpx;
            text-align: left;
        }

        &.h-turnover {
            display: flex;
            align-items: center;
        }

        &.h-profit {
            display: flex;
            align-items: center;
        }

        &.ascending {
            .caret {
                .sort-caret {
                    &.ascending {
                        border-bottom-color: $app-color-main;
                    }
                }
            }
        }

        &.descending {
            .caret {
                .sort-caret {
                    &.descending {
                        border-top-color: $app-color-main;
                    }
                }
            }
        }

        .caret {
            display: inline-flex;
            flex-direction: column;
            align-items: center;
            height: 34px;
            width: 24px;
            vertical-align: middle;
            cursor: pointer;
            overflow: initial;
            position: relative;

            .sort-caret {
                width: 0;
                height: 0;
                border: 6rpx solid transparent;
                position: absolute;
                left: 7px;

                &.ascending {
                    border-bottom-color: #434c67;
                    top: 22rpx;
                }

                &.descending {
                    border-top-color: #434c67;
                    bottom: 18rpx;
                }
            }
        }
    }
}
.returnHome{
	position: fixed;
	bottom: 24rpx;
	right:24rpx;
	width: 80rpx;
	height: 80rpx;
	background: #FFFFFF;
	box-shadow: 0px 0px 16px 0px rgba(0,0,0,0.2);
	display: flex;
	justify-content: center;
	align-items: center;
	font-size: 24rpx;
	color: #333;
	border-radius: 50%;
}
.returnUp{
	position: fixed;
	bottom: 114rpx;
	right:24rpx;
	width: 80rpx;
	height: 80rpx;
	background: #FFFFFF;
	box-shadow: 0px 0px 16px 0px rgba(0,0,0,0.2);
	display: flex;
	justify-content: center;
	align-items: center;
	font-size: 24rpx;
	color: #333;
	border-radius: 50%;
}
</style>
